package tests;

import java.rmi.RemoteException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import junit.framework.TestCase;
import client.ConsoleUI;

import common.Board;
import common.Coordinate;
import common.Game;
import common.IUI;
import common.Player;
import common.Profile;
import common.ReverseIntegerComparator;
import common.Tile;

public class ConsoleUITest extends TestCase {

    Game game;
    List<Tile> listOfTiles;
    Board board;
    Player p1, p2, p6;
    IUI p1ui, p2ui, p6ui;
    Map<Integer, List<Player>> map;
    List<String> userNames;
    List<IUI> userUI;
    
    Profile profile1;
    List<String> rivals;
    
    protected void setUp() {
        userNames = new ArrayList<String>();
        userUI = new ArrayList<IUI>();
        
        listOfTiles = new ArrayList<Tile>();
        for(int i=0; i<9; i++)
        {
            for(int j=0; j<12; j++)
            {
                listOfTiles.add(new Tile(new Coordinate(i,j)));
            }
        }
        board = new Board(listOfTiles);
        p1ui = new ConsoleUI();
        p2ui = new ConsoleUI();
        p6ui = new ConsoleUI();
        p1 = new Player("Amit", p1ui);
        p2 = new Player("Gilad", p2ui);
        p6 = new Player("Oded", p6ui);
        
        userNames.add("Amit");
        userNames.add("Gilad");
        userNames.add("Oded");
        
        userUI.add(p1ui);
        userUI.add(p2ui);
        userUI.add(p6ui);
        
        game = new Game(userNames, userUI,false);
        
        p1.increaseCash(2000);
        p2.increaseCash(2000);
        p6.increaseCash(3000);
        ArrayList<Player> one = new ArrayList<Player>(); 
        ArrayList<Player> two = new ArrayList<Player>(); 
        one.add(p6); two.add(p1); two.add(p2);
        
        ReverseIntegerComparator compartor = new ReverseIntegerComparator();
        
        map = new TreeMap<Integer,List<Player>>(compartor);
        map.put(2000, two);
        map.put(3000, one);
        
        profile1 = new Profile("Amit","abcd","bla@bla.co.il");
        rivals = new ArrayList<String>();
        rivals.add("Alon");
        rivals.add("Nir");
        profile1.addHistoryEntry(new Date(System.currentTimeMillis()),rivals,2);
        rivals.add("Oded");
        profile1.addHistoryEntry(new Date(System.currentTimeMillis()), rivals, 3);
        
       }
    
    public void testPrintEndGameResults() throws RemoteException { 
        p6.getUI().printEndGameResults(map);
    }
    
   public void testPrintHistory() throws RemoteException {
       p1.getUI().printHistory(profile1.getHistory());
       
   }
    
}
